﻿////double Divide(int a, int b) //noexcept
////{
////	// 当b == 0时抛出异常
////	if (b == 0)
////	{
////		throw "Division by zero condition!";
////	}
////	return (double)a / (double)b;
////}
////
////int main()
////{
////	try
////	{
////		int len, time;
////		//cin >> len >> time;
////		cout << Divide(1, 0) << endl;
////	}
////	catch (const char* errmsg)
////	{
////		cout << errmsg << endl;
////	}
////	catch (...)
////	{
////		cout << "Unkown Exception" << endl;
////	}
////	int i = 0;
////	cout << noexcept(Divide(1, 2)) << endl;
////	cout << noexcept(Divide(1, 0)) << endl;
////	cout << noexcept(++i) << endl;
////	return 0;
////}
//
//
////double Divide(int a, int b)
////{
////	// 当b == 0时抛出异常
////	if (b == 0)
////	{
////		throw "Division by zero condition!";
////	}
////	return (double)a / (double)b;
////}
////void Func()
////{
////	// 这⾥可以看到如果发⽣除0错误抛出异常，另外下⾯的array没有得到释放。
////	// 所以这⾥捕获异常后并不处理异常，异常还是交给外层处理，这⾥捕获了再
////	// 重新抛出去。
////	int* array = new int[10];
////	try
////	{
////		int len, time;
////		cin >> len >> time;
////		cout << Divide(len, time) << endl;
////	}
////	catch (int e)
////	{
////		// 捕获异常释放内存
////		cout << "delete []" << array << endl;
////		delete[] array;
////		throw 1; // 异常重新抛出，捕获到什么抛出什么
////	}
////	cout << "delete []" << array << endl;
////	delete[] array;
////}
////
////int main()
////{
////	try
////	{
////		Func();
////	}
////	catch (const char* errmsg)
////	{
////		cout << errmsg << endl;
////	}
////	catch (int e)
////	{
////		cout << e << endl;
////	}
////	catch (const exception& e)
////	{
////		cout << e.what() << endl;
////	}
////	catch (...)
////	{
////		cout << "Unkown Exception" << endl;
////	}
////	return 0;
////}
// 
////class HttpException
////{
////public:
////	HttpException(string a, int b, string c)
////		:_a(a)
////		, _b(b)
////		, _c(c)
////	{}
////
////private:
////	string _a;
////	int _b;
////	string _c;
////};
////
////void _SeedMsg(const string& s)
////{
////	if (rand() % 2 == 0)
////	{
////		throw HttpException("⽹络不稳定，发送失败", 102, "put");
////	}
////	else if (rand() % 7 == 0)
////	{
////		throw HttpException("你已经不是对象的好友，发送失败", 103, "put");
////	}
////	else
////	{
////		cout << "发送成功" << endl;
////	}
////}
////
////void SendMsg(const string & s)
////{// 发送消息失败，则再重试3次
////	for (size_t i = 0; i < 4; i++)
////	{
////		try
////		{
////			_SeedMsg(s);
////			break;
////		}
////
////		catch (const Exception& e)
////		{
////			// 捕获异常，if中是102号错误，⽹络不稳定，则重新发送
////			// 捕获异常，else中不是102号错误，则将异常重新抛出
////			if (e.getid() == 102)
////			{
////				// 重试三次以后否失败了，则说明⽹络太差了，重新抛出异常
////				if (i == 3)
////					throw;
////				cout << "开始第" << i + 1 << "重试" << endl;
////			}
////			else
////			{
////				throw;
////			}
////		}
////	}
////}
////
////int main()
////{
////	srand(time(0));
////	string str;
////	while (cin >> str)
////	{
////		try
////		{
////			SendMsg(str);
////		}
////		catch (const HttpException& e)
////		{
////			cout << e.what() << endl << endl;
////		}
////		catch (const Exception& e)
////		{
////			cout << e.what() << endl << endl;
////		}
////		catch (...)
////		{
////			cout << "Unkown Exception" << endl;
////		}
////	}
////	return 0;
////}
//
////class A
////{
////protected:
////	int _a = 10;
////	int _b = 20;
////};
////
////class B :public A
////{
////public:
////	int a = _a;
////};
////
////int main()
////{
////	A a;
////	B b;
////}
//
////#include<functional>
////int f(int a, int b)
////{
////	return a + b;
////}
////struct Functor
////{
////public:
////	int operator() (int a, int b)
////	{
////		return a + b;
////	}
////};
////class Plus
////{
////public:
////	Plus(int n = 10)
////		:_n(n)
////	{}
////	static int plusi(int a, int b)
////	{
////		return a + b;
////	}
////	double plusd(double a, double b)
////	{
////		return (a + b) * _n;
////	}
////
////
////private:
////	int _n;
////};
////
////int main()
////{
////	// 包装各种可调⽤对象
////	function<int(int, int)> f1 = f;
////	function<int(int, int)> f2 = Functor();
////	function<int(int, int)> f3 = [](int a, int b) {return a + b; };
////	cout << f1(1, 1) << endl;
////	cout << f2(1, 1) << endl;
////	cout << f3(1, 1) << endl;
////	// 包装静态成员函数
////	// 成员函数要指定类域并且前⾯加&才能获取地址
////	function<int(int, int)> f4 = &Plus::plusi;
////	cout << f4(1, 1) << endl;
////	// 包装普通成员函数
////	// 普通成员函数还有⼀个隐含的this指针参数，所以绑定时传对象或者对象的指针过去都可以
////	function<double(Plus*, double, double)> f5 = &Plus::plusd;
////	Plus pd;
////	cout << f5(&pd, 1.1, 1.1) << endl;
////	function<double(Plus, double, double)> f6 = &Plus::plusd;
////	cout << f6(pd, 1.1, 1.1) << endl;
////	cout << f6(pd, 1.1, 1.1) << endl;
////	function<double(Plus&&, double, double)> f7 = &Plus::plusd;
////	cout << f7(move(pd), 1.1, 1.1) << endl;
////	cout << f7(Plus(), 1.1, 1.1) << endl;
////	return 0;
////}
//
//#include<iostream>
//using namespace std;
//#include<functional>
//using placeholders::_1;
//using placeholders::_2;
//using placeholders::_3;
//int Sub(int a, int b)
//{
//	return (a - b) * 10;
//}
//int SubX(int a, int b, int c)
//{
//	return (a - b - c) * 10;
//}
//class Plus
//{
//public:
//	static int plusi(int a, int b)
//	{
//		return a + b;
//	}
//	double plusd(double a, double b)
//	{
//		return a + b;
//	}
//};
//int main()
//{
//	auto sub1 = bind(Sub, _1, _2);
//	cout << sub1(10, 5) << endl;
//	// bind 本质返回的⼀个仿函数对象
//	// 调整参数顺序（不常⽤）
//	// _1代表第⼀个实参
//	// _2代表第⼆个实参
//	// ...
//	auto sub2 = bind(Sub, _2, _1);
//	cout << sub2(10, 5) << endl;
//	// 调整参数个数 （常⽤）
//	auto sub3 = bind(Sub, 100, _1);
//	cout << sub3(5) << endl;
//	auto sub4 = bind(Sub, _1, 100);
//	cout << sub4(5) << endl;
//	// 分别绑死第123个参数
//	auto sub5 = bind(SubX, 100, _1, _2);
//	cout << sub5(5, 1) << endl;
//	auto sub6 = bind(SubX, _1, 100, _2);
//	cout << sub6(5, 1) << endl;
//	auto sub7 = bind(SubX, _1, _2, 100);
//	cout << sub7(5, 1) << endl;
//	// 成员函数对象进⾏绑死，就不需要每次都传递了
//	function<double(Plus&&, double, double)> f6 = &Plus::plusd;
//	Plus pd;
//	cout << f6(move(pd), 1.1, 1.1) << endl;
//	cout << f6(Plus(), 1.1, 1.1) << endl;
//	// bind⼀般⽤于，绑死⼀些固定参数
//	function<double(double, double)> f7 = bind(&Plus::plusd, Plus(), _1, _2);
//	cout << f7(1.1, 1.1) << endl;
//	// 计算复利的lambda
//	auto func1 = [](double rate, double money, int year)->double {
//		double ret = money;
//		for (int i = 0; i < year; i++)
//		{
//			ret += ret * rate;
//		}
//		return ret - money;
//	};
//	// 绑死⼀些参数，实现出⽀持不同年华利率，不同⾦额和不同年份计算出复利的结算利息
//	function<double(double)> func3_1_5 = bind(func1, 0.015, _1, 3);
//	function<double(double)> func5_1_5 = bind(func1, 0.015, _1, 5);
//	function<double(double)> func10_2_5 = bind(func1, 0.025, _1, 10);
//	function<double(double)> func20_3_5 = bind(func1, 0.035, _1, 30);
//	cout << func3_1_5(1000000) << endl;
//	cout << func5_1_5(1000000) << endl;
//	cout << func10_2_5(1000000) << endl;
//	cout << func20_3_5(1000000) << endl;
//
//	 return 0;
//}
